//
//  UserTopView.m
//  Arts1
//
//  Created by apple on 15/8/29.
//  Copyright (c) 2015年 Arts1. All rights reserved.
//

#import "UserTopView.h"
#import "AllHeader.h"
#import "UserCollectionViewController.h"
#import "UserViewController.h"

@interface UserTopView ()

@property (nonatomic ,strong) UserViewController *userView;

@end

@implementation UserTopView

- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame])
    {
        [self creactView];
    }
    return self;
}

/**
 *  创建视图控件
 */
- (void)creactView
{
    /**
     * 头像
     */
    _imageIcon = [[UIImageView alloc] initWithFrame:CGRectMake(10, 12, 47, 47)];
    _imageIcon.backgroundColor = kRandomColor;
    _imageIcon.layer.cornerRadius = 47/2;
    _imageIcon.layer.masksToBounds = YES;
    [self addSubview:_imageIcon];
    
    /**
     * 姓名
     */
    _nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(_imageIcon.right + 10, 18, 200, 20)];
//    _nameLabel.text = @"袁阿迅";
//    _nameLabel.font = [UIFont fontWithName:@"Arial-BoldMT" size:18];
    _nameLabel.font = [UIFont boldSystemFontOfSize:18];
    _nameLabel.textColor = kCustomColor(40, 40, 50, 1);
    [self addSubview:_nameLabel];
    
    /**
     * 地址
     */
    _addressLabel = [[UILabel alloc] initWithFrame:CGRectMake(_imageIcon.right + 10, _nameLabel.bottom  + 2, 200, 14)];
//    _addressLabel.text = @"静安·上海";
    _addressLabel.font = [UIFont italicSystemFontOfSize:10];
    _addressLabel.textColor = kCustomColor(150, 150, 150, 1);
    [self addSubview:_addressLabel];
    
    /**
     * 分割线
     */
    _lineLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, _imageIcon.bottom + 12, SCREEN_HEIGHT, 0.1)];
    _lineLabel.backgroundColor = [UIColor blackColor];
    _lineLabel.alpha = 1.0;
    [self addSubview:_lineLabel];
    
    
    /**
     * 收藏个数和收藏按钮
     */
    _CollectTitleView = [[TitleView alloc] initWithFrame:CGRectMake(10, _lineLabel.bottom + 3, SCREEN_WIDTH / 4.0, 40)];
    _CollectTitleView.index = 1;
    [_CollectTitleView.button setTitle:@"收藏" forState:UIControlStateNormal];
//    [_CollectTitleView.btnNum setTitle:@"469" forState:UIControlStateNormal];
    [self addSubview:_CollectTitleView];
    
    
    /**
     * 关注个数和关注按钮
     */
    _AttentionTitleView = [[TitleView alloc] initWithFrame:CGRectMake(_CollectTitleView.right + 10, _lineLabel.bottom + 5, (SCREEN_WIDTH - 20) / 4, 40)];
    _AttentionTitleView.index = 2;       // 用来标记tag值
    [_AttentionTitleView.button setTitle:@"关注" forState:UIControlStateNormal];
//    [_AttentionTitleView.btnNum setTitle:@"76" forState:UIControlStateNormal];
    [self addSubview:_AttentionTitleView];
    
    
    /**
     * 考试个数和考试按钮
     */
    _ExaminationTitleView = [[TitleView alloc] initWithFrame:CGRectMake(_AttentionTitleView.right + 10, _lineLabel.bottom + 5, (SCREEN_WIDTH - 20) / 4, 40)];
    _ExaminationTitleView.index = 3;
    [_ExaminationTitleView.button setTitle:@"考试" forState:UIControlStateNormal];
//    [_ExaminationTitleView.btnNum setTitle:@"10" forState:UIControlStateNormal];
    [self addSubview:_ExaminationTitleView];
    
    /**
     * 课程数和课程按钮
     */
    _CourseTitleView = [[TitleView alloc] initWithFrame:CGRectMake(_ExaminationTitleView.right + 10, _lineLabel.bottom + 5, (SCREEN_WIDTH - 20) / 4, 40)];
    _CourseTitleView.index = 4;
    [_CourseTitleView.button setTitle:@"课程" forState:UIControlStateNormal];
//    [_CourseTitleView.btnNum setTitle:@"36" forState:UIControlStateNormal];
    [self addSubview:_CourseTitleView];
    

}

//重写ModelSetter方法
- (void)setModel:(UserInfoModel *)model
{
    _model = model;
    
    //用户头像
//    [_imageIcon sd_setImageWithURL:[NSURL URLWithString:_model.userFace] placeholderImage:nil];
    
    [_imageIcon sd_setImageWithURL:[NSURL URLWithString:_model.userFace] placeholderImage:nil options:SDWebImageRetryFailed | SDWebImageLowPriority];
    
    //姓名
    _nameLabel.text = _model.nickName;
    
    //地址
    _addressLabel.text = [NSString stringWithFormat:@"%@",_model.Province];
    
    //收藏数量
    [_CollectTitleView.btnNum setTitle:_model.collectionNum forState:UIControlStateNormal];
    
    //关注个数
    [_AttentionTitleView.btnNum setTitle:_model.follow forState:UIControlStateNormal];
    
    //考试数量
    [_ExaminationTitleView.btnNum setTitle:_model.examNum forState:UIControlStateNormal];
    
    //课程数量
    [_CourseTitleView.btnNum setTitle:_model.courseNum forState:UIControlStateNormal];
}


@end
